<%-- 
    Document   : Home
    Created on : 04/08/2011, 12:42:06 PM
    UserType   : Poll Admin
    Author     : Lan Ye 42239015

--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../header.jsp" %>

<div id="content-container">
    <div id="content">
         <div id = "admin-poll">
        <center><font color="red"> <c:out value="${error}"></c:out></font></center>
        <c:choose>
            <c:when test="${polls.isEmpty()}">
            <br/>
                <center><h1><font color="red">No polls found</font></h1></center>
            </c:when>
            <c:otherwise>
                    <br/><br/>
        <table class="polladmintable">
            <tr>
               <th>Poll Name</th>
               <th>Poll Creator</th>
               <th>Remove Poll Creator</th>
               <th>Assign Poll Creator</th>
            </tr>
            <c:forEach items="${polls}" var="polls">
                <tr>
                    <td>${polls.getPollName()}</td>
                    <td>
                        <c:choose>
                            <c:when test="${polls.getPollCreatorID().isEmpty()}">
                                <font color="red">Not Assigned</font>
                            </c:when>
                            <c:otherwise>
                                <select id="creatorID${polls.getID()}">
                                    <c:forEach items="${polls.getCreatorName()}}" varStatus="pollCreator">  
                                        <option value="${polls.getPollCreatorID()[pollCreator.index]}">${polls.getCreatorName()[pollCreator.index]}</option>
                                    </c:forEach>
                                </select>
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <c:choose>
                            <c:when test="${polls.getPollCreatorID().isEmpty()}">
                                <button  disabled ="true" id ="removeButton" onclick="remove(${polls.getID()})">Remove</button>
                            </c:when>
                            <c:otherwise>
                                <button id ="removeButton" onclick="remove(${polls.getID()})">Remove</button>
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <a href="<c:url value="./assignPollCreator.html?id=${polls.getID()}"/>">Assign</a>
                    </td>
                </tr>
            </c:forEach>                                 
        </table>
        </c:otherwise>
        </c:choose>
         </div>
        <br/>
        <center> 
            <font color="green"> <c:out value="${remove}"></c:out></font>
            <font color="green"> <c:out value="${created}"></c:out></font>
            <font color="green"> <c:out value="${changed}"></c:out></font>
        </center>
    </div>
</div>				
<%@ include file="../footer.jsp" %>
<script language="JavaScript">
    function remove(pid){
        var pagesObj = document.getElementById("creatorID"+pid);
        var cid = pagesObj.options[pagesObj.selectedIndex].value;   
         window.location="home.html?cid="+cid+"&pid="+pid;
    }
</script>

<style>
    #admin-poll { 
        padding-left: 40px;
    }
    #master-poll { 
        padding-left: 40px;
    }
    #creator-poll {
        padding-left: 40px;
    }
    
    .polladmintable {
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    width:92%;
    border:1px solid #009933;
    text-align:center;
    }
    .polladmintable td, .polladmintable th .polladmintable tr {
    font-size:1em;    
    border:1px solid #009933;
    padding:3px 7px 2px 17px;
    }
    .polladmintable th {
    font-size:1.1em;
    text-align:center;
    padding-top:5px;
    padding-bottom:4px;
    background-color:#008833;
    color:#ffffff;
    }
</style>
